//
//  AppDelegate.swift
//  SinaWeibo
//
//  Created by zhuangqianwei on 16/11/12.
//  Copyright © 2016年 zhuangqianwei. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
       func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        //调用通知
        registerNotification()
        //设置window
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
//        let nav = UINavigationController(rootViewController: WBComposeController())
//        window?.rootViewController = nav
//        window?.rootViewController = WBTabBarController()
        window?.rootViewController = WBUserAccountViewModel.shared.userLogin ? WBWelcomeController() : WBTabBarController()
        window?.makeKeyAndVisible()
        return true
    }
    
    private func registerNotification(){
//        注册通知

        NotificationCenter.default.addObserver(self, selector: #selector(switchRootViewController(n:)), name:Notification.Name(kChoseRootViewController), object: nil)
    }
    
    @objc private func switchRootViewController(n:Notification) {
        //根据通知对象中object来判断显示什么控制器 
        let vc = (n.object == nil ? WBTabBarController() : WBWelcomeController())
        
        //设置根视图控制器
        window?.rootViewController = vc
    }
    //移除通知
    deinit {
        //规范
        NotificationCenter.default.removeObserver(self)
    }
    // 添加cover高斯模糊
    func applicationDidEnterBackground(_ application: UIApplication) {
        
        //清楚缓存数据
        WBStatusDAL.clearCacheStatus()
    }
   }

